<template>
  <div class="app-container">
  

    <!-- 表格 v-loading.body="listLoading"-->
    <el-table
      ref="multipleTable"
      @selection-change="handleSelectionChange"
      :data="tableData"
      border
      fit
      highlight-current-row
    >
      <el-table-column type="selection" width="50"> </el-table-column>

      <el-table-column align="center" label="序号" width="70">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column label="审核作品ID" width="" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="dialogVisible = true">
                {{ scope.row.content_id }}
          </el-button>
            <el-dialog
            title="提示"
            :visible.sync="dialogVisible"
            width="60%"
            :before-close="handleClose">
                <el-form ref="form1" :model="chapter" label-width="120px">
                    <el-form-item label="章节名" >
                         <el-col :span="5">
                            <el-input v-model="chapter.title" disabled></el-input>
                         </el-col>
                    </el-form-item> 
                    <el-form-item label="内容" >
                        <el-col :span="6" v-for="(item, index) in chapter.content" :key="index">
                            <el-image :src="item" fit="cover" :preview-src-list="chapter.content" :z-index="2555"></el-image>
                        </el-col>
                    </el-form-item> 
                </el-form>
            </el-dialog> 
        </template>
      </el-table-column>

      <el-table-column label="审核状态" width="" align="center" prop="title">
        <template slot-scope="scope">
          {{ scope.row.review_result }}
        </template>
      </el-table-column>

      <el-table-column
        label="创建时间"
        width=""
        align="center"
        prop="title"
        sortable
      >
        <template slot-scope="scope">
          {{ scope.row.created_at }}
        </template>
      </el-table-column>

      <el-table-column
        label="审核时间"
        width=""
        prop="title"
        align="center"
        sortable
      >
        <template slot-scope="scope">
          {{ scope.row.review_at }}
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
            >通过</el-button
          >
          <el-button
            size="small"
            type="danger"
             @click="open"
            >不通过</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="listQuery.currPage"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="listQuery.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
    <!-- 新增弹窗 -->
    <el-dialog title="表单新增" :visible.sync="dialogFormVisible">
      <el-form
        class="small-space"
        :model="temp"
        label-position="left"
        label-width="70px"
        style="width: 400px; margin-left: 50px"
      >
        <el-form-item label="字段1">
          <el-input v-model="temp.chnlId"></el-input>
        </el-form-item>

        <el-form-item label="字段2">
          <el-input v-model="temp.hisChnlId"></el-input>
        </el-form-item>

        <el-form-item label="字段3">
          <el-input v-model="temp.chnlName"></el-input>
        </el-form-item>

        <el-form-item label="字段4">
          <el-input v-model="temp.state"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>

        <el-button type="primary" @click="handleCreateSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

export default {
  data() {
    return {
        // 弹框
         dialogVisible: false,
         chapter:{
             title:'梦想中的世界',
             content:[
                 'https://c1.kuangxiangit.com/custom/comic/7/8/1.jpg',
                 'https://c1.kuangxiangit.com/custom/comic/7/8/2.jpg',
                 'https://c1.kuangxiangit.com/custom/comic/7/8/3.jpg',
                 'https://c1.kuangxiangit.com/custom/comic/7/8/4.jpg',
                 'https://c1.kuangxiangit.com/custom/comic/7/8/5.jpg',
                 'https://c1.kuangxiangit.com/custom/comic/7/8/6.jpg',
                 'https://c1.kuangxiangit.com/custom/comic/7/8/7 (2).jpg'
             ]
         },
      // list: null,
      // listLoading: true,

      list: null, //表格list
      total: null,
      listLoading: true,
      listQuery: {
        currPage: 1,
        pageSize: 10,

        // importance: undefined,
        title: "",
        type: null, //类型
      },
      tableData: [
        {
          review_id: 1,
          content_id: 2,
          review_result: "审核中",
          created_at: "2019-05-06",
          review_at: "2019-05-08",
        },
      ],
      temp: {
        chnlId: "22",
        hisChnlId: "",
        chnlName: "",
        state: "",
        isavailable: "",
        orderNum: 10,
      },
      typeOptions: [
        { key: "001", display_name: "类型1" },
        { key: "002", display_name: "类型2" },
        { key: "003", display_name: "类型3" },
      ],
      dialogFormVisible: false,
      multipleSelection: [],
    };
  },
  mounted() {
    var vm = this;

    vm.getList();
  },
  methods: {
      // 不通过按钮点击事件
      open() {
        this.$prompt('请输入反馈内容', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({ value }) => {
          this.$message({
            type: 'success',
            message: '反馈内容: ' + value
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          });       
        });
      },
      // 关闭弹框事件
       handleClose(done) {
            done();
      },
    //获取列表数据
    getList() {
      var vm = this;

      vm.listLoading = true;

      //请求参数
      let par = {
        count: vm.listQuery.pageSize,
        start: (vm.listQuery.currPage - 1) * vm.listQuery.pageSize,
      };

  
    },
    //编辑
    handleEdit(index, row) {
      var vm = this;
      console.log("编辑的row：", index, "-----", row);
      //跳页面进行修改
      //this.$router.push('/example/form');
      this.$router.push({ path: "/example/form", query: { id: row.chnlId } }); //带参跳转
    },
    //单个删除
    handleDelete(index, row) {
      var vm = this;
      console.log("单个删除选择的row：", index, "-----", row);
      //前端删除。
      vm.list.splice(index, 1);
    },
    //批量删除
    handleDelAll() {
      var vm = this;
      console.log("批量删除选择的row：", vm.multipleSelection);
    },
    //搜索
    handleFilter() {
      this.getList();
    },
    //操作分页
    handleSizeChange(val) {
      console.log("--------一页多少条：", val);
      this.listQuery.pageSize = val;
      this.getList();
    },
    //操作分页
    handleCurrentChange(val) {
      console.log("--------当前页：", val);
      this.listQuery.currPage = val;
      this.getList();
    },
    //新增
    handleCreate() {
      this.dialogFormVisible = true;
    },
    //新增提交
    handleCreateSubmit() {
      var vm = this;
      console.log("新增入参：", vm.temp, vm.list);

      //这里作演示用，正式新增 请提交到接口
      vm.list.push(vm.temp);
      console.log("新增后", vm.list);

      this.dialogFormVisible = false;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    handleDownload() {
      var vm = this;

      require.ensure([], () => {
        const { export_json_to_excel } = require("vendor/Export2Excel");
        const tHeader = ["字段1", "字段2", "字段3", "字段4", "字段5"];
        const filterVal = [
          "chnlId",
          "hisChnlId",
          "chnlName",
          "state",
          "isavailable",
        ];
        const list = vm.list;
        const data = vm.formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, "导出的列表excel");
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map((v) => filterVal.map((j) => v[j]));
    },
  },
};
</script>
